<!DOCTYPE html>
<!-- saved from url=(0033)http://www.taffydb.com/extensions -->
<html lang="en" class="gr__taffydb_com"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
     
  <title>TaffyDB - Extensions</title>
  <meta name="description" content="">
  
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <script id="twitter-wjs" src="./index_files/widgets.js.download"></script><script type="text/javascript" async="" src="./index_files/ga.js.download"></script><script type="text/javascript" src="./index_files/XRegExp.js.download"></script> <!-- XRegExp is bundled with the final shCore.js during build -->
	<script type="text/javascript" src="./index_files/shCore.js.download"></script>
	<script type="text/javascript" src="./index_files/shBrushJScript.js.download"></script>

	<link type="text/css" rel="stylesheet" href="./index_files/shCore.css">
	<link type="text/css" rel="Stylesheet" href="./index_files/shThemeDefault.css">
	<script type="text/javascript">SyntaxHighlighter.all();</script>
    <!-- Le styles -->

    <link href="./index_files/bootstrap.css" rel="stylesheet">
    <style type="text/css">
      body {
        padding-top: 60px;
        padding-bottom: 40px;
      }
      .sidebar-nav {
        padding: 9px 0;
      }
     .toolbar {
			opacity:0;
		}

	 .method {

		}
		.method td {
			border-bottom:thin solid silver;
			border-top:thin solid silver;
			vertical-align:text-top;
		}
		.method td:first-child {
			color:gray;
			background-color:#F2EDEF;
			font-size:160%;
			text-align:center;
			vertical-align:middle;
		}
		b {
			background-color:#F2EDEF;
		}
    </style>
    <link href="./index_files/bootstrap-responsive.css" rel="stylesheet">

    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <!-- Le fav and touch icons -->
    <link rel="shortcut icon" href="http://www.taffydb.com/ico/favicon.ico">

    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="http://www.taffydb.com/ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="http://www.taffydb.com/ico/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="http://www.taffydb.com/ico/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="http://www.taffydb.com/ico/apple-touch-icon-57-precomposed.png">
  <script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-130587-11']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

  <script type="text/javascript" charset="utf-8" async="" src="./index_files/timeline.619317855a58aa2366562a395f9e40ef.js.download"></script></head>

  <body data-gr-c-s-loaded="true">

    <div class="navbar navbar-fixed-top">
      <div class="navbar-inner">

        <div class="container-fluid">
          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <a class="brand" href="/">TaffyDB</a>
          <div class="pull-right">
            <a class="btn" href="https://github.com/typicaljoe/taffydb">
            taffy.js
            </a>
          </div>
          <div class="nav-collapse">
            <ul class="nav">
              <li><a href="/">Home</a></li>
              <li><a href="https://github.com/typicaljoe/taffydb/archive/master.zip">Download</a></li>
              <li><a href="/beginner.html">Beginner's Guide</a></li>
              <li><a href="/writing_queries.html">Writing Queries</a></li>
              <li><a href="/working_with_data.html">Working With Data</a></li>
              <li class="active"><a href="extentions.html">Extensions</a></li>
             </ul>
          </div><!--/.nav-collapse -->
        </div>
      </div>
    </div>

    <div class="container-fluid">
      <div class="row-fluid">
        <div class="span3">

          <div class="well sidebar-nav">
            <ul class="nav nav-list">
              <li class="nav-header">On Github</li>
              <li><a href="https://github.com/typicaljoe/taffydb">GitHub Home</a></li>

              <li><a href="https://github.com/typicaljoe/taffydb/archive/master.zip">Download</a></li>
              <li><a href="https://github.com/typicaljoe/taffydb/blob/master/taffy.js">Source Code</a></li>
                           <form id="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="ENS2E6Z99PDZN">
</form>
              <li class="nav-header">Community and Support</li>
              <li><a href="https://github.com/typicaljoe/taffydb/issues?state=open">Open Issues</a></li>


            </ul>


          </div><!--/.well -->

        </div><!--/span-->
        <div class="span9">
          <div class="hero-unit">

               
            <h1>Extending TaffyDB</h1>
            
            <p>TaffyDB is easy to extend. Simply use the extend method to add a new method to all TaffyDB collections on your page.</p>
				<p>Here is an example that creates an "avg" method that takes a column and returns the avg value.</p>
				<pre class="brush: js">// Create a new empty database
TAFFY.extend("avg",function (c) {
	// This runs the query or returns the results if it has already run
	this.context({
           results: this.getDBI().query(this.context())
    });
    // setup the sum
    var total = 0;
    // loop over every record in the results and sum up the column.
    TAFFY.each(this.context().results,function (r) {
		total = total + r[c];
    })
    
    // divide the total by the number of records and return
    return total/this.context().results.length;
});
</pre>
			<p>What can you build?</p>


          </div>
           <footer>
         


    </footer>


        </div><!--/span-->
      </div><!--/row-->

      <hr>

      <footer>
        <div align="center"><img src="./index_files/taffydbboxV3.jpg"></div>
      </footer>

    </div><!--/.fluid-container-->

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="./index_files/jquery.js.download"></script>
    <script src="./index_files/bootstrap-transition.js.download"></script>
    <script src="./index_files/bootstrap-alert.js.download"></script>
    <script src="./index_files/bootstrap-modal.js.download"></script>

    <script src="./index_files/bootstrap-dropdown.js.download"></script>
    <script src="./index_files/bootstrap-scrollspy.js.download"></script>
    <script src="./index_files/bootstrap-tab.js.download"></script>
    <script src="./index_files/bootstrap-tooltip.js.download"></script>
    <script src="./index_files/bootstrap-popover.js.download"></script>
    <script src="./index_files/bootstrap-button.js.download"></script>

    <script src="./index_files/bootstrap-collapse.js.download"></script>
    <script src="./index_files/bootstrap-carousel.js.download"></script>
    <script src="./index_files/bootstrap-typeahead.js.download"></script>

  

<iframe id="rufous-sandbox" scrolling="no" frameborder="0" allowtransparency="true" allowfullscreen="true" style="position: absolute; visibility: hidden; display: none; width: 0px; height: 0px; padding: 0px; border: none;" title="Twitter analytics iframe" src="./index_files/saved_resource(1).html"></iframe></body></html>
